import { useNavigate } from 'react-router-dom'
import axios from '../../axios/api'
import React, { useEffect, useState } from 'react'


function Home() {
    const [data, setData] = useState([])

    const navigaet = useNavigate()
    const getData = async () => {
        const res = await axios.post('/api/trip/train', {
            "start": "北京",
            "end": "广州",
            "date": "2023-09-21",
            "isSpeed": true,
            "isSeat": true,
            "isDesc": true,
            "page": 1
        })
        console.log(res);


        setData(res.data.data)
    }

    useEffect(() => {
        getData()
    }, [])

    return (
        <div>
            {
                data.map((item, index) => (
                    <div
                        key={index}
                        onClick={() => navigaet(`/detail?id=${item.id}`)}
                        style={{ padding: '10px 0' }}
                    >
                        <div style={{ display: 'flex', justifyContent: 'space-around', border: '1px solid #ccc', padding: '10px' }}>
                            <div>
                                <p>{item.startTime}</p>
                                <p>11:22</p>
                            </div>
                            <div>
                                <p>{item.start}</p>
                                <p>{item.end}</p>
                            </div>
                            <div>
                                <p>G19</p>
                                <p>硬卧</p>
                            </div>
                            <div>
                                <p>￥345</p>
                                <p>{item.isSeat ? '有票' : '无票'}</p>
                            </div>
                        </div>
                    </div>
                ))
            }
        </div>
    )
}

export default Home